<template>
  <div id="user">
    <el-container style="height: 700px; border: 1px solid #eee">
      <el-header style="text-align: right; font-size: 12px">
        <el-menu
            :default-active="activeIndex2"
            class="el-menu-demo"
            mode="horizontal"
            @select="handleSelect"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
          <el-menu-item index="1" @click="index">首页</el-menu-item>
          <el-menu-item index="4" @click="completeOrder">订单管理</el-menu-item>
          <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>查看</el-dropdown-item>
              <el-dropdown-item>新增</el-dropdown-item>
              <el-dropdown-item>删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <span>{{ email }}这是您今天第{{num}}次访问！</span>
        </el-menu>
      </el-header>
      <el-container>
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
          <el-menu :default-openeds="['1','2', '3']">
            <el-submenu index="1">
              <template slot="title"><i class="el-icon-location-information"></i>停车位信息</template>
              <el-submenu index="1-4">
                <template slot="title">停车位列表</template>
                <el-menu-item v-for="l in address" :key="l" index="1-4-1" @click="userParking(l)">{{ l }}</el-menu-item>
              </el-submenu>
            </el-submenu>
            <el-submenu index="2">
              <template slot="title"><i class="el-icon-s-order"></i>订单信息</template>
              <el-menu-item-group>
                <el-menu-item index="2-1" @click="completeOrder">已完成订单</el-menu-item>
                <el-menu-item index="2-2" @click="noCompleteOrder">未完成订单</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
            <el-submenu index="3">
              <template slot="title"><i class="el-icon-setting"></i>报障模块</template>
              <el-menu-item-group>
                <el-menu-item index="3-1" @click="findProposal">我要反馈</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <router-view></router-view>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "user",
  data() {
    return {
      address: [],
      parking: [],
      l: '',
      user: '',
      order: [],
      activeIndex: '1',
      activeIndex2: '1',
      proposal: [],
      num: '',
    }
  },
  props: {
    email: null,
  },
  methods: {
    userParking(l) {
      this.l = l,
          this.user = this.email
      this.$http.get("http://localhost:8088/user/findParkingByAddress", {
        params: {
          address: l,
        }
      }).then(resp => {
        this.parking = resp.data
        this.$router.push({
          name: 'user_parking',
          query: {
            parking: this.parking,
            email: this.user,
          }
        }).catch(err => {
          console.log(err)
        })
      }).catch({})

    },
    completeOrder() {
      this.user = this.email
      this.$http.get("http://localhost:8088/user/findCompleteOrder", {
        params: {
          email: this.user,
        }
      }).then(resp => {
        this.order = resp.data
        this.$router.push({
          name: 'user_order',
          query: {
            order: this.order,
            email: this.user,
          }
        }).catch(err => {
          console.log(err)
        })
      })
    },
    noCompleteOrder() {
      this.user = this.email
      this.$http.get("http://localhost:8088/user/findNoCompleteOrder", {
        params: {
          email: this.user,
        }
      }).then(resp => {
        this.order = resp.data
        this.$router.push({
          name: 'user_order',
          query: {
            order: this.order,
            email: this.user,
          }
        }).catch(err => {
          console.log(err)
        })
      })
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    index() {
      this.user = this.email
      this.$router.push({
        name: 'index',
        query: {
          email: this.user,
        }
      }).catch(err => {
        console.log(err)
      })
    },
    findProposal() {
      this.user = this.email
      this.$http.get("http://localhost:8088/user/findProposalByEmail", {
        params: {
          email: this.user,
        }
      }).then(resp => {
        this.proposal = resp.data
        this.$router.push({
          name: 'user_proposal',
          query: {
            email: this.user,
            proposal: this.proposal,
          }
        }).catch(err => {
          console.log(err)
        })
      })
    }
  },
  created() {
    this.$http.get("http://localhost:8088/user/findParkingAddress").then(resp => {
      this.address = resp.data;
      this.$http.get("http://localhost:8088/redis/find").then(resp => {
        this.num = resp.data;
      })
    }).catch({})
  },
  beforeMount() {
    this.user = this.email
    this.$router.push({
      name: 'index',
      query: {
        email: this.user,
      }
    }).catch(err => {
      console.log(err)
    })
  }
}
</script>

<style scoped>
.el-header {
  background-color: #545c64;
  color: #333;
  line-height: 60px;
  width: 100%;
  margin-bottom: 5px;
  padding: 0;
}

.el-aside {
  color: #333;
}

h2 {
  float: left;
  font-size: 30px;
  padding-left: 30px;
  padding-top: 0;
  margin: 0;

}

.el-icon-setting {
  color: red;
}

span {
  font-size: 20px;
  color: aqua;
}

#user {


}
</style>